<layout name="page" />
<block name="content">
	<style>
		.bold {
			font-weight: bold;
		}
	</style>
	{:widget('page_header/adv_search',array('name'=>$folder_name,'search'=>'M'))}
	<form method="post" name="form_adv_search" id="form_adv_search">
		<div class="x-panel hidden"  id="adv_search">
			<div class="x-panel-header">
				<h4>高级搜索</h4>
				<div class="split"></div>
				<a  class="btn" id="submit_adv_search">搜索</a>
				<a  class="btn btn-return" id="close_adv_search">关闭</a>
			</div>
			<div class="x-panel-body">
				<div class="frame">
					<div class="box col-12">
						
							<label class="input-label" for="li_name">标题：</label>
							
								<input  class="input" type="text" id="li_name" name="li_name" >
							</div>
						</div>
					</div>
					<div class="box col-12">
						
							<label class="input-label" for="li_content">内容：</label>
							
								<input  class="input" type="text" id="li_content" name="li_content" >
							</div>
						</div>
					</div>
				</div>
				<div class="frame">
					<div class="box col-12">
						<in name="folder" value="darftbox,outbox">
							
								<label class="input-label" for="li_to">收件人：</label>
								
									<input  class="input" type="text" id="li_to" name="li_to" >
								</div>
							</div>
							<else/>
							
								<label class="input-label" for="li_from">发件人：</label>
								
									<input  class="input" type="text" id="li_from" name="li_from" >
								</div>
							</div>
						</in>
					</div>
					<div class="box col-12">
						
							<div class="layui-inline">
								<label class="input-label">登录时间：</label>
								<div class="input-inline" style="width: 100px;">
									<input type="text" class="input input-start-date" name="be_create_time" readonly="readonly"/>
								</div>
								<div class="layui-form-mid">
									-
								</div>
								<div class="input-inline" style="width: 100px;">
									<input type="text" class="input input-end-date" name="en_create_time" readonly="readonly"/>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<div class="operate-panel">
		<a data-fun="del" class="btn btn-warning x-click">删除</a>
		<a data-fun="del_forever" class="btn btn-del x-click">永久删除</a>
		<a id="forword" class="btn">转发</a>
		<a data-fun="spam" class="btn  hidden x-click">举报</a>
		<div class="btn-group">
			<a class="btn  dropdown-toggle" data-toggle="dropdown" href="#"> 标记为 <span class="fa fa-caret-down"></span> </a>
			<ul class="dropdown-menu">
				<li data-fun="readed" class="x-click">
					<a>已读</a>
				</li>
				<li data-fun="unread" class="x-click">
					<a>未读</a>
				</li>
			</ul>
		</div>
		<div class="btn-group" id="move_to">
			<a class="btn  dropdown-toggle" data-toggle="dropdown" href="#"> 转移到 <span class="fa fa-caret-down"></span> </a>
			<ul class="dropdown-menu">
				{$folder_list}
			</ul>
		</div>
		<div class="split"></div>
		<a id="receve" class="btn">收信</a>
	</div>

	<div class="ul-table">
		<ul>
			<li class="thead" >
				<span class="col-2 checkbox">
					<input type="checkbox"class="toggle-select-all" data="id[]"/>
				</span>
				<span class="col-16  x1">标题</span>
				<span class="col-20 pull-left">
					<in name="folder" value="darftbox,outbox">
						收件人
						<else/>
						发件人
					</in></span>
				<span class="col-9 pull-right " >时间</span>
			</li>
			<if condition="!empty($list)">
				<li class="no-data">
					没找到数据
				</li>
				<else/>
				<form method="post" action="" name="form_data" id="form_data">
					<foreach name="list" val="vo">
						<li class="tbody <eq name='vo.read' value='1'>normal</eq><eq name='vo.read' value='0'>bold</eq>" >
							<span class="col-2 checkbox">
								<input  type="checkbox" name="id[]" value="{$vo.id}" />
							</span>
							<span class="col-16  x1">
								<notempty name = "vo['add_file']" >
									<i class="fa fa-paperclip"></i>
									<else/>
									<i class="fa fa-paperclip" style="text-indent:-9999px;"></i>
								</notempty>
								<in name="folder" value="darftbox">
									<a  title="{$vo.name|htmlspecialchars}" href="{:url('edit','id='.$vo['id'])}"> {$vo.name}&nbsp;&nbsp;&nbsp;
									<eq name="vo.name|strlen" value="0">
										无标题
									</eq></a>
									<else/>
									<a title="{$vo.name|htmlspecialchars}" href="{:url('read','id='.$vo['id'])}"> {$vo.name}&nbsp;&nbsp;&nbsp;
									<eq name="vo.name|strlen" value="0">
										无标题
									</eq> </a>
								</in> </span>
							<span class="col-20  pull-left">
								<in name="folder" value="darftbox,outbox">
									{$vo.to|show_contact}
									<else/>
									{$vo.from|show_contact}
								</in> </span>
							<span  class="col-9" >{$vo.create_time|to_date='Y-m-d'}</span>
						</li>
					</foreach>
				</form>
			</if>
		</ul>
		<notempty name="list">
			<div class="pagination">
				{$page}
			</div>
		</notempty>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			$(".x-click").click(function() {
				var vars = $("#form_data").serialize();
				if (vars.length == 0) {
					layer.msg("没有选择邮件邮件");
					return false;
				}
				var action = $(this).data("fun");
				switch (action) {
				case "readed":
					send_ajax("{:url('mark','action=readed')}", vars, function(data) {
						if (data.status) {
							$("input[name='id[]']:checked").each(function() {
								$(this).parents("li").removeClass("bold");
								$(this).parents("li").addClass("normal");
							});
							$("input[name='id[]']:checked").prop('checked', false);
							$("#id-toggle-all").prop('checked', false);
						}
					});
					break;
				case "unread":
					send_ajax("{:url('mark','action=unread')}", vars, function(data) {
						if (data.status) {
							$("input[name='id[]']:checked").each(function() {
								$(this).parents("li").removeClass("normal");
								$(this).parents("li").addClass("bold");
							});
							$("input[name='id[]']:checked").prop('checked', false);
							$("#id-toggle-all").prop('checked', false);
						}
					});
					break;
				case "del":
					send_ajax("{:url('mark','action=del')}", vars, function(data) {
						if (data.status) {
							layer.msg(data.info, function() {
								location.reload(true);
							});
						}
					});
					break;
				case "del_forever":

					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function() {
							send_ajax("{:url('mark','action=del_forever')}", vars, function(data) {
								if (data.status) {
									layer.msg(data.info, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
					break;
				case "spam":
					send_ajax("{:url('mark','action=spam')}", vars, function(data) {
						if (data.status) {
							layer.msg(data.info, function() {
								location.reload(true);
							});
						}
					});
					break;
				default:
					layer.msg("未定义此操作");
				}
			});

			$("#forword").click(function() {
				if ($("input[name='id[]']:checkbox:checked").length == 1) {
					window.open(fix_url('{:url("reply")}?id=' + $("input[name='id[]']:checkbox:checked:first").val() + "&type=forward"), "_self");
				} else {
					layer.msg("请选择一封要转发的邮件");
					return false;
				};
			});

			$("#receve").click(function() {
				send_ajax("{:url('receve')}");
			});

			function move_to(val) {
				var vars = $("#form_data").serialize();
				if (vars.length > 0) {
					send_ajax("{:url('mark','action=move_to')}", 'val=' + val + '&' + vars, function(data) {
						if (data.status) {
							layer.msg(data.info, function() {
								location.reload(true);
							});
						}
					});
				} else {
					layer.msg("请至少选择一封要转移的邮件");
					return false;

				}
			}


			$("#move_to li").click(function() {
				move_to($(this).attr("id"));
			});
			set_return_url(null);

		});
	</script>
</block>